﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserList.aspx.cs" Inherits="Taxes.Users.UserList" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function Cancel() {
            window1.hide();
            tfLoginName.setValue("");
            tfDepartment.setValue("");
            tfName.setValue("");
            tbHidden.setValue("添加");
            ckSupper.setValue(false);
        }
        function JumpImport() {
            window.location.href = "UserImport.aspx";
        }

        var command = function (cmd, record, rowIndex) {
            if (cmd === 'deleteUser') {
                var result = confirm("删除后无法恢复，确定删除吗?")
                if (result) {
                    Ext.net.DirectMethods.DeleteUser(record.id,
                    {
                        success: function (result) {
                            if (result == 1) {
                                Ext.Msg.alert('提示', "删除成功");
                                grid.reload();
                            }
                            else {
                                Ext.Msg.alert('提示', "删除失败");
                            }
                        }
                    });
                }
            }
            else if (cmd == "updateUser") {
                tfLoginName.setValue(record.data.user_name);
                tfDepartment.setValue(record.data.user_department);
                tfName.setValue(record.data.user_tname);
                tbHiddenID.setValue(record.id);
                ckSupper.setValue(record.data.user_type);
                tbHidden.setValue("修改");
                window1.show();
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager runat="server" />
    <ext:Window runat="server" ID="window1" Width="600" Height="200" Title="添加用户" Padding="5"
        Layout="FormLayout" Hidden="true">
        <Items>
            <ext:Hidden runat="server" ID="tbHidden"  Text="增加">
            </ext:Hidden>
            <ext:Hidden runat="server" ID="tbHiddenID" Text=""></ext:Hidden>
            <ext:TextField ID="tfLoginName" runat="server" AnchorHorizontal="100%" AllowBlank="false"
                FieldLabel="用户名<font color='red'>*</font>">
            </ext:TextField>
            <ext:TextField ID="tfDepartment" runat="server" AllowBlank="false" AnchorHorizontal="100%"
                FieldLabel="部门<font color='red'>*</font>">
            </ext:TextField>
            <ext:TextField ID="tfName" runat="server" AllowBlank="false" AnchorHorizontal="100%"
                FieldLabel="姓名<font color='red'>*</font>">
            </ext:TextField>
            <ext:Checkbox ID="ckSupper" runat="server" FieldLabel="是否为管理员<font color='red'>*</font>">
            </ext:Checkbox>
        </Items>
        <Buttons>
            <ext:Button ID="btnSave" runat="server" Icon="Disk" Text="保存">
                <DirectEvents>
                    <Click OnEvent="btnAdd_Click">
                        <EventMask ShowMask="True" Msg="正在保存..." MinDelay="1000" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button ID="btnCancel" runat="server" Icon="Cancel" Text="取消">
                <Listeners>
                    <Click Fn="Cancel" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Window>
    <div>
        <asp:ObjectDataSource ID="obsUser" runat="server" SelectMethod="GetModelList" TypeName="Taxes.BLL.ysys_user">
            <SelectParameters>
                <asp:Parameter Name="strWhere" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <ext:Store ID="storeUser" runat="server" DataSourceID="obsUser" >
            <Reader>
                <ext:JsonReader IDProperty="ID">
                    <Fields>
                        <ext:RecordField Name="ID" Type="Int">
                        </ext:RecordField>
                        <ext:RecordField Name="user_name" Type="String">
                        </ext:RecordField>
                        <ext:RecordField Name="user_pwd" Type="String">
                        </ext:RecordField>
                        <ext:RecordField Name="user_tname" Type="String">
                        </ext:RecordField>
                        <ext:RecordField Name="user_department" Type="String">
                        </ext:RecordField>
                        <ext:RecordField Name="user_type" Type="Int">
                        </ext:RecordField>
                        <ext:RecordField Name="in_date" Type="Date">
                        </ext:RecordField>
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        <ext:GridPanel StoreID="storeUser" ID="grid" runat="server" Title="用户管理" Frame="true"
            StripeRows="true" Height="400" TrackMouseOver="True" AutoScroll="true"   >
           <LoadMask ShowMask="true" Msg="正在加载，请稍后."  />
           <BottomBar>
                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" StoreID="storeUser" DisplayInfo="true">
                </ext:PagingToolbar>
            </BottomBar>
            <ColumnModel>
                <Columns>
                    <ext:Column ColumnID="colLoginName" DataIndex="user_name" Header="用户名">
                    </ext:Column>
                    <ext:Column ColumnID="colPwd" DataIndex="user_pwd" Header="密码">
                    </ext:Column>
                    <ext:Column ColumnID="colName" DataIndex="user_tname" Header="姓名">
                    </ext:Column>
                    <ext:Column ColumnID="colDepartment" DataIndex="user_department" Header="部门">
                    </ext:Column>
                    <ext:CheckColumn ColumnID="colType" DataIndex="user_type" Header="是否为管理员">
                    </ext:CheckColumn>
                    <ext:DateColumn ColumnID="colDate" DataIndex="in_date" Header="添加日期" Format="yyyy-MM-dd">
                    </ext:DateColumn>
                    <ext:CommandColumn ColumnID="colDelete" Header="操作">
                        <Commands>
                            <ext:GridCommand Icon="ApplicationEdit" ToolTip-Text="修改" CommandName="updateUser">
                                <ToolTip Text="修改" />
                            </ext:GridCommand>
                            <ext:CommandSeparator />
                            <ext:GridCommand Icon="Delete" ToolTip-Text="删除" CommandName="deleteUser">
                                <ToolTip Text="删除" />
                            </ext:GridCommand>
                        </Commands>
                    </ext:CommandColumn>
                </Columns>
            </ColumnModel>
            <Listeners>
                <Command Fn="command" />
            </Listeners>
            <Buttons>
                <ext:Button ID="btnAdd" runat="server" Text="添加用户" Icon="Add">
                    <Listeners>
                        <Click Handler="#{window1}.show()" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnImport" runat="server" Text="导入用户" Icon="Application">
                    <Listeners>
                        <Click Fn="JumpImport" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:GridPanel>
    </div>
    </form>
</body>
</html>
